cd "${utils}"

// 2004-2008
forvalues i = 2004/2008 {
	cap erase "${tmp}/dads`i'.dta"
	local files: dir "${rawsource}/DADS_DADS Postes_`i'" files "*.sas7bdat"
	foreach file in `files' {
		disp "`file'"
		import sas IDENT_S SIREN NBHEUR NBHEUR_1 S_BRUT S_BRUT_1 CATJUR CATJUR_1 APET APET_1 APEN  COMT COMT_1 COMR PCS PCS_1 FILT FILT_1 AGE DUREE using "${rawsource}/DADS_DADS Postes_`i'/`file'", clear
		cap append using "${tmp}/dads`i'.dta"
		save "${tmp}/dads`i'.dta", replace
	}
	rename *, lower
	destring fil*, replace
	gen year = `i'
	save, replace
}

// 2009-2011
forvalues i = 2009/2011 {
	cap erase "${tmp}/dads`i'.dta"
	local files: dir "${rawsource}/DADS_DADS Postes_`i'" files "*.sas7bdat"
	foreach file in `files' {
		disp "`file'"
		if "`file'" != "post_nationale_1_12.sas7bdat" {
			import sas IDENT_S SIREN NBHEUR NBHEUR_1 S_BRUT S_BRUT_1 CATJUR CATJUR_1 APET APET_1 APEN  COMT COMT_1 COMR PCS PCS_1 FILT FILT_1 AGE DUREE using "${rawsource}/DADS_DADS Postes_`i'/`file'", clear
			cap append using "${tmp}/dads`i'.dta"
			save "${tmp}/dads`i'.dta", replace
		}
	}
	rename *, lower
	destring fil*, replace
	gen year = `i'
	save, replace
}

// 2012-2013
forvalues i = 2012/2013 {
	cap erase "${tmp}/dads`i'.dta"
	local files: dir "${rawsource}/DADS_DADS Postes_`i'" files "*.sas7bdat"
	
	foreach file in `files' {
		disp "`file'"
		if "`file'" != "post_nationale_1_12.sas7bdat" {
			import sas IDENT_S SIREN NBHEUR NBHEUR_1 S_BRUT S_BRUT_1 CATJUR CATJUR_1 APET APET_1 APEN  COMT COMT_1 COMR PCS PCS_1 FILT FILT_1 AGE DUREE using "${rawsource}/DADS_DADS Postes_`i'/`file'", clear
			cap append using "${tmp}/dads`i'.dta"
			save "${tmp}/dads`i'.dta", replace
		}
	}
}
forvalues i = 2012/2013 {
	local files: dir "${rawsource}/DADS_DADS Postes_`i'\Ile de France" files "*.sas7bdat"
	
	foreach file in `files' {
		disp "`file'"
		if "`file'" != "post_nationale_1_12.sas7bdat" {
			import sas IDENT_S SIREN NBHEUR NBHEUR_1 S_BRUT S_BRUT_1 CATJUR CATJUR_1 APET APET_1 APEN  COMT COMT_1 COMR PCS PCS_1 FILT FILT_1 AGE DUREE using "${rawsource}/DADS_DADS Postes_`i'/Ile de France/`file'", clear
			append using "${tmp}/dads`i'.dta"
			save "${tmp}/dads`i'.dta", replace
		}
	}
	rename *, lower
	destring fil*, replace
	gen year = `i'
	save, replace
}

// 2014-2017
forvalues i = 2014/2017 {
	cap erase "${tmp}/dads`i'.dta"
	local files: dir "${rawsource}/DADS_DADS Postes_`i'\Régions" files "*.sas7bdat"
	
	foreach file in `files'  {
		disp "`file'"
		if "`file'" != "post_nationale_1_12.sas7bdat" {
			import sas IDENT_S SIREN NBHEUR NBHEUR_1 S_BRUT S_BRUT_1 CATJUR CATJUR_1 APET APET_1 APEN  COMT COMT_1 COMR PCS PCS_1 FILT FILT_1 AGE DUREE using "${rawsource}/DADS_DADS Postes_`i'/Régions/`file'", clear
			cap append using "${tmp}/dads`i'.dta"
			save "${tmp}/dads`i'.dta", replace
		}
	}

}
forvalues i = 2014/2017 {
	
	local files: dir "${rawsource}/DADS_DADS Postes_`i'\Départements" files "*.sas7bdat"
	
	foreach file in `files'  {
		disp "`file'"
		if "`file'" != "post_nationale_1_12.sas7bdat" {
			import sas IDENT_S SIREN NBHEUR NBHEUR_1 S_BRUT S_BRUT_1 CATJUR CATJUR_1 APET APET_1 APEN  COMT COMT_1 COMR PCS PCS_1 FILT FILT_1 AGE DUREE using "${rawsource}/DADS_DADS Postes_`i'/Départements/`file'", clear
			append using "${tmp}/dads`i'.dta"
			save "${tmp}/dads`i'.dta", replace
		}
	}
	rename *, lower
	destring fil*, replace
	gen year = `i'
	save, replace
}


// 2018-2019
forvalues i = 2018/2019 {
	cap erase "${tmp}/dads`i'.dta"
	local files: dir "${rawsource}/DADS_DADS Postes_`i'" files "*.sas7bdat"
	foreach file in `files' {
		disp "`file'"
		import sas IDENT_S SIREN NBHEUR NBHEUR_1 S_BRUT S_BRUT_1 CATJUR CATJUR_1 APET APET_1 APEN  COMT COMT_1 COMR PCS PCS_1 FILT FILT_1 AGE DUREE using "${rawsource}/DADS_DADS Postes_`i'/`file'", clear
		cap append using "${tmp}/dads`i'.dta"
		save "${tmp}/dads`i'.dta", replace
	}
	rename *, lower
	destring fil*, replace
	gen year = `i'
	save, replace
}